#include "Backpropagation/Backpropagation.hpp"
#include <iostream>

using namespace NeuralPlusPlus::Core;
using namespace NeuralPlusPlus::Core::Backpropagation;

using namespace std;

void main()
	{
	ActivationLayer *inputLayer = new LinearLayer(2);
	ActivationLayer *hiddenLayer = new SigmoidLayer(2);
	ActivationLayer *outputLayer = new SigmoidLayer(1);

	BackpropagationConnector c1(inputLayer, hiddenLayer, ConnectionModeType::Complete);
	BackpropagationConnector c2(hiddenLayer, outputLayer, ConnectionModeType::Complete);

	BackpropagationNetwork network(inputLayer, outputLayer);

	double i1[] = {0,0}; double o1[] = {0};
	double i2[] = {0,1}; double o2[] = {1};
	double i3[] = {1,0}; double o3[] = {1};
	double i4[] = {1,1}; double o4[] = {0};

	TrainingSample ts1(i1, 2, o1, 1);
	TrainingSample ts2(i2, 2, o2, 1);
	TrainingSample ts3(i3, 2, o3, 1);
	TrainingSample ts4(i4, 2, o4, 1);

	TrainingSet trainingSet(2,1);
	trainingSet.Add(&ts1);
	trainingSet.Add(&ts2);
	trainingSet.Add(&ts3);
	trainingSet.Add(&ts4);

	network.Learn(&trainingSet, 100000);

	double *output1 = network.Run(i1);
	double *output2 = network.Run(i2);
	double *output3 = network.Run(i3);
	double *output4 = network.Run(i4);
	
	cout<<"expected output: "<<o1[0]<<". network output: "<<output1[0]<<endl;
	cout<<"expected output: "<<o2[0]<<". network output: "<<output2[0]<<endl;
	cout<<"expected output: "<<o3[0]<<". network output: "<<output3[0]<<endl;
	cout<<"expected output: "<<o4[0]<<". network output: "<<output4[0]<<endl;

	delete inputLayer;
	delete hiddenLayer;
	delete outputLayer;
	delete[] output1;
	delete[] output2;
	delete[] output3;
	delete[] output4;

	system("pause");
	}